import Request from '@/utils/request'
import type {
  CreateUserPayloadType,
  LoginPayloadType,
  LoginResponseType,
  QueryUserPayloadType,
  QueryUserResponseType,
  updateUserPayloadType
} from '@/types/api/user'

// 登录
export const login = (data: LoginPayloadType) => {
  return Request.Post<LoginResponseType>({
    url: '/login',
    data
  })
}

// 查询用户列表
export const queryUserListApi = (data: QueryUserPayloadType) => {
  return Request.Get<QueryUserResponseType>({
    url: '/users',
    data
  })
}

// 创建用户
export const createUserApi = (data: CreateUserPayloadType) => {
  return Request.Post({
    url: '/user',
    data
  })
}

// 编辑用户
export const updateUserApi = (data: updateUserPayloadType) => {
  const { id, ...rest } = data
  return Request.Put({
    url: `/user/${id}`,
    data: rest
  })
}

// 删除用户
export const deleteUserApi = (id: string) => {
  return Request.Delete({
    url: `/user/${id}`
  })
}
